
package com.hc.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.hc.dao.IRoleDao;
import com.hc.domain.Role;
@Repository
public class RoleDaoImpl extends BaseDaoImpl<Role> implements IRoleDao {

	@Override
	public List<Role> findAll() {
		return super.find("FROM Role");
		
	}

	@Override
	public Role getRoleByRoleName(String roleName) {
		return super.get("FROM Role r WHERE r.role=?", new Object[]{roleName});
		
	}

	@Override
	public void updateOrSave(Role role) {
		super.saveOrUpdate(role);
	}

	@Override
	public Role getRoleById(int id) {
		return super.get("FROM Role r WHERE r.id=?", new Object[]{id});
		
	}

	@Override
	public void deleteRole(Role role) {
		super.delete(role);
	}

	@Override
	public List<Role> getRoleByEmployeeId(int id) {
		String sql = "select r.* from role r, user_and_role ur WHERE ur.adminId=? AND ur.roleId=r.id";
		try {
			return super.executeSql(Role.class, sql, new Object[]{id});
		} catch (Exception e) {
			return null;
		}
	}

}

